aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2023-12-19 09:44:09 -0500
committerSebastien Castiel <sebastien@castiel.me>2023-12-19 09:44:09 -0500
commitf881aff5f9993c3a6b4b0d8ed7e67d2f812f39d6 (patch)
tree685731e70ad838dbc2b3d70450e090e1e5fc31c9 /src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx
parent1e66efe5169dfad9a0c62ba42fbf31ce977bf49e (diff)
Revert "Use modal dialogs for expense creation & edition (#10)"
This reverts commit 1e66efe5169dfad9a0c62ba42fbf31ce977bf49e.
Diffstat (limited to 'src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx')
-rw-r--r--src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx b/src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx
new file mode 100644
index 0000000..188d08f
--- /dev/null
+++ b/src/app/groups/[groupId]/expenses/[expenseId]/edit/page.tsx
@@ -0,0 +1,42 @@
+import { ExpenseForm } from '@/components/expense-form'
+import { deleteExpense, getExpense, getGroup, updateExpense } from '@/lib/api'
+import { expenseFormSchema } from '@/lib/schemas'
+import { Metadata } from 'next'
+import { notFound, redirect } from 'next/navigation'
+
+export const metadata: Metadata = {
+ title: 'Edit expense',
+}
+
+export default async function EditExpensePage({
+ params: { groupId, expenseId },
+}: {
+ params: { groupId: string; expenseId: string }
+}) {
+ const group = await getGroup(groupId)
+ if (!group) notFound()
+ const expense = await getExpense(groupId, expenseId)
+ if (!expense) notFound()
+
+ async function updateExpenseAction(values: unknown) {
+ 'use server'
+ const expenseFormValues = expenseFormSchema.parse(values)
+ await updateExpense(groupId, expenseId, expenseFormValues)
+ redirect(`/groups/${groupId}`)
+ }
+
+ async function deleteExpenseAction() {
+ 'use server'
+ await deleteExpense(expenseId)
+ redirect(`/groups/${groupId}`)
+ }
+
+ return (
+ <ExpenseForm
+ group={group}
+ expense={expense}
+ onSubmit={updateExpenseAction}
+ onDelete={deleteExpenseAction}
+ />
+ )
+}